home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
C++
/
Applications
/
Mic-1 v1.0
/
Project and Source
/
Source
/
mic_dump.cpp
< prev
next >
Wrap
Text File
|
1996-05-17
|
5KB
|
212 lines
/*
"mic_dump.cpp"
This file contains code for dumping the contents of the various objects of Mic-1
to the screen or to an arbitrary file.
*/
#include <iostream.h>
#include <fstream.h>
#include "mic_main.h"
#include "mic_dump.h"
#include "mic_global_functions.h"
// constants for Dump()
const short kFromDataPath = 0;
const short kFromControl = 1;
const short kFromMemory = 2;
const short kFromEverything = 3;
const short kToDeathFile = 0;
const short kToIndexedFile = 1;
const short kToFinalFile = 2;
const short kToScreen = 3;
// local prototypes
short FindWhereToDump (void);
void DumpSomething (Mic_1_Class& Mic, short whereFrom, ostream& dest);
void DumpDataPath (Mic_1_Class& Mic, ostream dest);
void DumpControl (Mic_1_Class& Mic, ostream dest);
void DumpMemory (Mic_1_Class& Mic, ostream dest);
void DumpEverything (Mic_1_Class& Mic, ostream dest);
void doDump (Mic_1_Class& Mic)
{
Boolean done = false;
short whereTo;
char c;
cout << endl;
cout << "__DUMP___________________________________" << endl;
cout << " m - dump the main memory" << endl;
cout << " a - dump all (the whole processor)" << endl;
cout << " c - dump the control section" << endl;
cout << " d - dump the data path" << endl;
cout << " x - escape back to the previous menu" << endl;
cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
while (!done)
{
cout << "dump >> ";
cin >> c;
switch (c)
{
case 'm': case 'M':
whereTo = FindWhereToDump();
Dump(Mic, kFromMemory, whereTo);
done = true;
break;
case 'a': case 'A':
whereTo = FindWhereToDump();
Dump(Mic, kFromEverything, whereTo);
done = true;
break;
case 'c': case 'C':
whereTo = FindWhereToDump();
Dump(Mic,kFromControl, whereTo);
done = true;
break;
case 'd': case 'D':
whereTo = FindWhereToDump();
Dump(Mic, kFromDataPath, whereTo);
done = true;
break;
case 'x': case 'X': done = true; break;
default: cout << "huh?" << endl; break;
}
}
if ((c != 'x') && (whereTo != kToScreen))
cout << "Dump file written" << endl;
}
short FindWhereToDump (void)
{
char c = 0;
while ((c != 's') && (c != 'f') && (c != 'S') && (c != 'F'))
{
cout << "Dump to the screen or to a file? (s/f) >> ";
cin >> c;
}
if ((c == 'f') || (c == 'F'))
return kToIndexedFile;
else //((c == 's') || (c == 'S'))
return kToScreen;
}
// Dump - dump the contents of an object into any file or to the screen.
// I chose not to let the objects handle this because lots of code
// for the Dump function within each object would be repeated.
void Dump (Mic_1_Class& Mic, const short whereFrom, const short whereTo)
{
char fileName[32];
char *fileNamePtr;
Str32 tempString, tempString2;
StringPtr tempStringPtr = tempString,
tempString2Ptr = tempString2;
ofstream dumpfile;
if (whereTo != kToScreen)
{
switch (whereFrom)
{
case kFromDataPath: GetIndString(tempStringPtr, 128, kFromDataPath + 3); break;
case kFromControl: GetIndString(tempStringPtr, 128, kFromControl + 3); break;
case kFromMemory: GetIndString(tempStringPtr, 128, kFromMemory + 3); break;
case kFromEverything: GetIndString(tempStringPtr, 128, kFromEverything + 3); break;
}
switch (whereTo)
{
case kToDeathFile:
GetIndString(tempStringPtr, 128, 1);
NumToString(Data.Cycle, tempString2Ptr);
Catenate(tempStringPtr, tempString2Ptr);
break;
case kToIndexedFile:
NumToString(Data.Cycle, tempString2Ptr);
Catenate(tempStringPtr, tempString2Ptr);
break;
case kToFinalFile:
GetIndString(tempStringPtr, 128, 2);
NumToString(Data.Cycle, tempString2Ptr);
Catenate(tempStringPtr, tempString2Ptr);
break;
default: break;
}
fileNamePtr = fileName;
fileNamePtr = P2CStr(tempStringPtr);
dumpfile.open(fileNamePtr);
DumpSomething(Mic, whereFrom, dumpfile);
}
else // dump to screen, or cout
{
// nothing special to initialize here
cout << endl;
DumpSomething(Mic, whereFrom, cout);
cout << endl << endl;
}
}
void DumpSomething (Mic_1_Class& Mic, short whereFrom, ostream& dest)
{
switch (whereFrom)
{
case kFromDataPath:
DumpDataPath(Mic, dest);
break;
case kFromControl:
DumpControl(Mic, dest);
break;
case kFromMemory:
DumpMemory(Mic, dest);
break;
case kFromEverything:
DumpEverything(Mic, dest);
break;
}
}
void DumpDataPath (Mic_1_Class& Mic, ostream dest)
{
dest << "***** Data Path Dump ***** Cycle " << Data.Cycle << " *****" << endl << endl;
dest << Mic.A_Latch << endl;
dest << Mic.B_Latch << endl;
dest << Mic.MBR << endl;
dest << Mic.MAR << endl;
dest << Mic.AMUX << endl;
dest << Mic.ALU << endl;
dest << Mic.Shifter << endl;
dest << Mic.ScratchPad << endl;
}
void DumpControl (Mic_1_Class& Mic, ostream dest)
{
dest << "***** Control Dump ***** Cycle " << Data.Cycle << " *****" << endl << endl;
dest << Mic.MMUX << endl;
dest << Mic.MPC << endl;
dest << Mic.MIR << endl;
}
void DumpMemory (Mic_1_Class& Mic, ostream dest)
{
dest << "***** Memory Dump ***** Cycle " << Data.Cycle << " *****" << endl << endl;
dest << Mic.Memory << endl;
}
void DumpEverything (Mic_1_Class& Mic, ostream dest)
{
dest << "***** Processor Dump ***** Cycle " << Data.Cycle << " *****";
dest << endl;
DumpControl(Mic, dest);
dest << endl;
DumpDataPath(Mic, dest);
dest << endl;
DumpMemory(Mic, dest);
}